package com.hangyutech.strelitzia.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.OSSObject;
import com.hangyutech.strelitzia.config.OssClientFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.io.InputStream;

public class AliyunOssUtil {

    @Autowired
    private OssClientFactory ossClientFactory;

//    @Autowired
//    private AliYunConfig ossConfig;

    public String readFile(String filename) {
        String str = "";
        OSS object = ossClientFactory.getObject();
        OSSObject object1 = object.getObject("wicon", filename);
        InputStream objectContent = object1.getObjectContent();
        System.out.println(objectContent);
        byte[] bytes = new byte[0];
        try {
            bytes = new byte[objectContent.available()];
            objectContent.read(bytes);
            str = new String(bytes);
            System.out.println(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
